﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZuoAlgorithms.Class020;

// 用这个例子讲解递归如何执行
// 数组中最大的值
public class GetMaxValue
{
    public int MaxValue(int[] arr)
    {
        return F(arr, 0, arr.Length - 1);
    }

    public int F(int[] arr, int left, int right)
    {
        if (left == right)
        {
            return arr[left];
        }
        int middle = (left + right) / 2;
        int leftMax = F(arr, left, middle);
        int rightMax = F(arr, middle + 1, right);
        return Math.Max(leftMax, rightMax);
    }

}
